package com.zhuoyue.common.enumeration;

/**
 * @author wjming
 * @ClassName: RequestPathEnum
 * @Description: 不同版本下请求路径枚举替换
 * @Date 2021-06-28 9:29
 */
public enum RequestPathEnum {
    /**
     * 注册时候的路径v1,v2
     */
    REGISTER_URL("/api/user/register", "/api/v2/user/register"),
    LOGIN_URL("/api/user/login", "/api/v2/user/login");

    /**
     * 版本1的路径
     */
    private String pathV1;
    /**
     * 需要重定向的路径
     */
    private String pathV2;

    RequestPathEnum(String pathV1, String pathV2) {
        this.pathV1 = pathV1;
        this.pathV2 = pathV2;
    }

    public String getPathV1() {
        return pathV1;
    }

    public String getPathV2() {
        return pathV2;
    }

    /**
     * 根据Key得到枚举的Value
     * 普通for循环遍历，比较判断
     *
     * @param pathV1
     * @return
     */
    public static String getV2Path(String pathV1) {
        RequestPathEnum[] requestPathEnums = RequestPathEnum.values();
        for (int i = 0; i < requestPathEnums.length; i++) {
            if (requestPathEnums[i].getPathV1().equals(pathV1)) {
                return requestPathEnums[i].getPathV2();
            }
        }
        return null;
    }
}
